<template>
    <div>
        <div class="header-info">
            <p>{{action_name}}-子系统</p>
            <div>
                <el-button size="mini" @click="$router.push('/system/sub-system-info/add')" v-if="action=='edit'">新建</el-button>
                <el-button size="mini" @click="save_click" type="primary"> 保存</el-button>
            </div>
        </div>
        <el-row :gutter="12" type="flex">
            <el-col>
                <el-card shadow="always">
                    <div slot="header">
                        <span>基本信息</span>
                    </div>
                    <kv label="名称"><el-input v-model="info.name" chk="*"/></kv>
                    <kv label="code"><el-input v-model="info.code"/></kv>
                    <kv label="网址"><el-input v-model="info.url"/></kv>
                    <kv label="直接打开">
                       <selector  type="radio" v-model="info.directOpen" :data="{true:'是',false:'否','':'全部'}" />
                    </kv>
                    <kv label="登录名"><el-input v-model="info.loginName"/></kv>
                    <kv label="密码"><el-input v-model="info.password"/></kv>
                    <kv label="更新时间">
                        <el-date-picker v-model="info.updateAt" placeholder="选择日期时间"  type="datetime" />
                    </kv>
                </el-card>
            </el-col>
            <el-col>
                <el-card shadow="always">
                    <div slot="header">
                        <span>扩展信息</span>
                    </div>
                </el-card>
            </el-col>
        </el-row>
    </div>
</template>
<style scoped>
</style>
<script>
/**
 * Created by CodeGenerator
 */

    export default {
        components: {

        },
        data() {
            return {

                info: {}, //子对象需要声明。
            }
        },
        props: {
            id: {type: String, default: ""}
        },
        computed:{
            action() {
                return this.id ? "edit" : "add";
            },
            action_name(){
                return {add: "添加", edit: "修改"}[this.action]
            }
        },
        mounted() {
            this.loadData()
        },
        methods: {
            loadData() {
                if (!this.id) return;
                this.$http.post("/system/sub-system-info/detail/" + this.id).then(res => {
                    this.info = res.data.data;
                });
            },
            save_click() {
                //校验
                if (jv.main.chk() == false) {
                    return;
                }

                this.$http.post("/system/sub-system-info/save", this.info).then(res => {
                    jv.info(this.action_name + " 成功");
                    if (this.action == "add") {
                        this.$router.push("/system/sub-system-info/edit/" + res.data.data)
                    }
                    else if (this.action == "edit") {
                        this.$router.push("/system/sub-system-info/list")
                    }
                })
            },

        }
    }
</script>
